Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix break in DirectoryServices SearchResultCollection #113775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IDisposable
Copy link
Contributor

@IDisposable IDisposable commented Mar 21, 2025

Added enumeration handling when the internal ArrayList has already been loaded but an enumeration follows. This fixes the issue with 9.x Linq statements against the collection caused by the access of the .Count

Fixes #113265

I am not entirely sure the best way to test this, as we never had tests for this class until now so I created a new DirectorySearcherTests.cs (conditionally run when LDAP is available) using the setup shown in the bur report.

Added enumeration handling when the internal ArrayList has already been loaded but an enumeration follows. This fixes the issue with 9.x Linq statements against the collection caused by the access of the .Count

Fixes dotnet#113265
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 21, 2025
@IDisposable
Copy link
Contributor Author

I think the code is the simplest way to fix this issue without making tons more changes. I'm not sure my test class is useful/valid because I'm not on a LDAP domain-joined machine so it simply bypasses for me in local runs.

:pointup: @BillArmstrong @stephentoub @tarekgh

/// <devdoc>
/// Supports a simple type-specific wrapper for the underlying cached list
/// </devdoc>
private sealed class AlreadyReadResultsEnumerator : IEnumerator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class

can this be a struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will adjust after the Blues game.

@tarekgh tarekgh added this to the 10.0.0 milestone Mar 23, 2025
Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @IDisposable

@stephentoub @steveharter could you please have a quick look? Note, this is a candidate for 9.0 service porting .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.DirectoryServices community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SearchResultCollection does not work with the IEnumerable extension methods in .Net 9.
2 participants